package 职责链.Demo4;

import java.util.ArrayList;
import java.util.List;

// 实战模式，敏感词过滤
interface SensitiveWordFilter {
    boolean doFilter(String content);
}

class SexyWordFilter implements SensitiveWordFilter {

    @Override
    public boolean doFilter(String content) {
        boolean legal = true;
        return legal;
    }
}

class PoliticalWordFilter implements SensitiveWordFilter {

    @Override
    public boolean doFilter(String content) {
        boolean legal = true;
        return legal;
    }
}

class SensitiveWordFilterChain {
    private List<SensitiveWordFilter> filters = new ArrayList<>();

    public void addFilter(SensitiveWordFilter filter) {
        this.filters.add(filter);
    }

    public boolean filter(String content) {
        for(SensitiveWordFilter filter : filters) {
            if(!filter.doFilter(content)) {
                return false;
            }
        }
        return true;
    }
}
public class Application {
    public static void main(String[] args) {
        SensitiveWordFilterChain filterChain = new SensitiveWordFilterChain();
        filterChain.addFilter(new PoliticalWordFilter());
        filterChain.addFilter(new SexyWordFilter());
        boolean legal = filterChain.filter("hhhhhh");
        if(legal) {
            //发表
        } else {
            // 不发表
        }
    }
}
